﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace X9Tech.HashWall.Core.Messaging
{
    public class MessagingManager
    {
        public delegate void WallMessageDelegate(Models.WallMessage message);
        public event WallMessageDelegate WallMessageAdded;
        public event WallMessageDelegate WallMessageRemoved;
        
        private HashWallContext context = null;
        private Simulation.MessageSimulator sim = null;
        internal MessagingManager(HashWallContext targetContext)
        {
            context = targetContext;
            sim = new HashWall.Core.Simulation.MessageSimulator(this);
        }

        public Simulation.MessageSimulator Simulator { get { return sim; } }

        private List<Models.WallMessage> wallMsgList = new List<Models.WallMessage>();
        public List<Models.WallMessage> AllMessages { get { return wallMsgList; } }

        public void AddMessage(Models.WallMessage message)
        {
            wallMsgList.Add(message);

            try
            {
                this.WallMessageAdded(message);
            }
            catch (Exception) { }
        }

        public void RemoveMessage(Models.WallMessage message)
        {
            if (!wallMsgList.Contains(message))
            {
                return;
            }

            wallMsgList.Remove(message);

            try
            {
                this.WallMessageRemoved(message);
            }
            catch (Exception) { }
        }
    }
}
